using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using System.Linq;

namespace SOEI.Solution.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="RoomVerifyV1Permissions" /> for all permission names. RoomVerifyV1
    ///</summary>
    public class RoomVerifyV1AuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

        public RoomVerifyV1AuthorizationProvider()
        {

        }

        public RoomVerifyV1AuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public RoomVerifyV1AuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            // 在这里配置了Member 的权限。
            var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));

            var administration = pages.Children.FirstOrDefault(p => p.Name == AppLtmPermissions.Pages_Administration) ?? pages.CreateChildPermission(AppLtmPermissions.Pages_Administration, L("Administration"));

            var permission = administration.CreateChildPermission(RoomVerifyV1Permissions.Node, L("RoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.Query, L("QueryRoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.Create, L("CreateRoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.Edit, L("EditRoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.Delete, L("DeleteRoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.BatchDelete, L("BatchDeleteRoomVerifyV1"));
            permission.CreateChildPermission(RoomVerifyV1Permissions.ExportExcel, L("ExportToExcel"));

            //// 添加自定义代码开始


            //// 添加自定义代码 结束
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, SolutionConsts.LocalizationSourceName);
        }
    }
}
